package com.example.concurrency.lb.synchronized01;

import java.util.concurrent.TimeUnit;

/**
 * @author: dangwen
 * @createDate: 2021/2/1
 * 死锁
 */
public class StringLockDemo {
    String s1 = "hello";
    String s2 = "hello";

    public void test1() {
        synchronized (s1){
            System.out.println("t1 start...."+Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t1 end...."+Thread.currentThread().getName());
        }
    }

    public void test2(){
        synchronized (s2){
            System.out.println("t2 begin...."+Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        StringLockDemo demo = new StringLockDemo();
        new Thread(demo :: test1, "test1").start();
        new Thread(demo :: test2, "test2").start();
    }
}
